﻿using System;
using System.Text;
using System.Collections.Generic;

namespace TidyBlog.Data
{
    /// <summary>
    /// 数据分页类
    /// </summary>
    public class DataPaging<T>
    {
        /// <summary>
        /// 每页显示记录数
        /// </summary>
        public readonly ushort PageSize;
        /// <summary>
        /// 当前页
        /// </summary>
        public readonly int CurrentPage;
        /// <summary>
        /// 总行数
        /// </summary>
        public readonly int RowCount;
        /// <summary>
        /// 总页数
        /// </summary>
        public readonly ushort PageCount;


        /// <summary>
        /// 
        /// </summary>
        /// <param name="rowCount">记录总数</param>
        /// <param name="pageSize">每页记录数</param>
        /// <param name="currentPage">当前页</param>
        public DataPaging(int rowCount, ushort pageSize, int currentPage)
        {
            PageSize = pageSize > 0 ? pageSize : (ushort)1;
            CurrentPage = currentPage == 0 ? 1 : currentPage;
            RowCount = rowCount;
            PageCount = (ushort)(rowCount > 0 ? Math.Ceiling((decimal)rowCount / pageSize) : 0);

            if (CurrentPage < 0 || CurrentPage > PageCount)
            {
                CurrentPage = PageCount;
            }
        }


        /// <summary>
        /// 获取或设置当前页数据
        /// </summary>
        public List<T> Data { get; set; }
    }
}